#include <bits/stdc++.h>
#define int long long
using namespace std;
int T, sum;
string str;
void solve() {
    int n;
    cin >> n;
    str = "";
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        str += s;
    }
    sum = 0;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = i - 1; j >= 0; j--) {
            //cout << (signed)i << ' ' << (signed)j << endl;
            if (str[i] == str[j]) {
                sum += str[i] - '0';
                break;
            }
        }
    }
    cout << sum << endl;
}
signed main()
{
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
